package com.fanjia.crm.service.impl;

import com.fanjia.crm.mapper.CourseOrderMapper;
import com.fanjia.crm.model.CourseOrder;
import com.fanjia.crm.model.MonthIncome;
import com.fanjia.crm.model.PageResult;
import com.fanjia.crm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by FanJia on 2020/9/17 10:35
 */
@Service
@Transactional
public class CourseOrderServiceImpl implements ICourseOrderService {

    @Autowired
    CourseOrderMapper orderMapper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        //定义一个Map-参数先不放在map,后面再处理
        Map<String,Object> params = new HashMap<>();
        params.put("condition",condition);
        params.put("start" , (page-1)*pageSize);
        params.put("length" , pageSize);
        //定义结果
        PageResult<CourseOrder> result = new PageResult<>();

        result.setCount(orderMapper.findCountByMap(params));
        result.setData(orderMapper.findListByMap(params));
        return result;
    }

    @Override
    public void save(CourseOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return orderMapper.findByOrderId(order_id);
    }

    @Override
    public void deleteByOrderId(String order_id) {
         orderMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(CourseOrder order) {
        orderMapper.update(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return orderMapper.getMonthIncomes();
    }
}
